/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Vndedores.java
 *
 * Created on 10/04/2011, 11:04:10
 */
package sisgraf.view;
import java.util.List;
import sisgraf.model.Vendedor;
import sisgraf.controler.VendedorControler;
import sisgraf.model.Usuario;
/**
 *
 * @author POSITIVO R41
 */
public class Vendedores extends javax.swing.JDialog {
    private int opcao=0;
    private VendedorControler vendedorControler;
    private Vendedor vendedor;
    private boolean incluiu=false;
    private Usuario usuario;
    /** Creates new form Vndedores */
    public Vendedores(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    public void setOpcao(int opcao)
    {
        this.opcao = opcao;
        formComponentResized(null);
        setLocationRelativeTo(null);
        jTxFdMatVen.setText(vendedor.getMat_ven());
        jTxFdNomVen.setText(vendedor.getNom_ven());
        jTxFdEndLog.setText(vendedor.getEnd_log());
        jTxFdEndCom.setText(vendedor.getEnd_com());
        jTxFdEndBai.setText(vendedor.getEnd_bai());
        jTxFdEndCid.setText(vendedor.getEnd_cid());
        jTxFdEmail.setText(vendedor.getEmail());
        jTxFdTelFix.setText(vendedor.getTel_fix());
        jTxFdTelCel.setText(vendedor.getTel_cel());
        jTxFdDatNas.setText(vendedor.getDat_nasForm());
        jTxNom_ven.setText(vendedor.getUsuario().getNome());
        jCbBxUf.setSelectedIndex(-1);
        if (this.opcao == Menu.OP_PESQ_ALT){
            jTxFdCodigo.setText(vendedor.getId().toString());
            if (vendedor.getAtivo().equals("S"))
                jCkBxAtivo.setSelected(true);
            else
                jCkBxAtivo.setSelected(false);
            jTxFdEndNum.setText(vendedor.getEnd_num()==null?"":vendedor.getEnd_num().toString());
            jTxFdEndCep.setText(vendedor.getEnd_cep()==null?"":vendedor.getEnd_cep().toString());
            if (vendedor.getEnd_uf()!=null){
                for (int i = 0; i<Menu.UF.length; i++){
                    if (vendedor.getEnd_uf().equals(Menu.UF[i]))
                        jCbBxUf.setSelectedIndex(i);
                }
            }
            jTxFdComVen.setText(vendedor.getCom_ven()==null?"":vendedor.getCom_ven().toString());
        } else {
            jTxFdCodigo.setText("");
            jTxFdEndNum.setText("");
            jTxFdEndCep.setText("");
            jTxFdComVen.setText("");
            jCkBxAtivo.setSelected(false);
        }
        jTxFdCodigo.setEnabled(false);
        setVisible(true);
        jTxFdNomVen.setFocusable(true);
    }
    public void setVendedor(Vendedor vendedor){
        this.vendedor = vendedor;
    }
    public void setControler(VendedorControler vendedorControler){
        this.vendedorControler = vendedorControler;
    }
    public boolean getncluiu(){
        return this.incluiu;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPnlSuperior = new javax.swing.JPanel();
        javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
        jLbSubTitulo = new javax.swing.JLabel();
        jPnlCentral = new javax.swing.JPanel();
        jPnlConteudo = new javax.swing.JPanel();
        javax.swing.JLabel jLabel5 = new javax.swing.JLabel();
        jTxFdCodigo = new javax.swing.JTextField();
        javax.swing.JLabel jLabel6 = new javax.swing.JLabel();
        jTxFdNomVen = new javax.swing.JTextField();
        javax.swing.JLabel jLabel7 = new javax.swing.JLabel();
        jTxFdMatVen = new javax.swing.JTextField();
        jCkBxAtivo = new javax.swing.JCheckBox();
        javax.swing.JPanel jPanel1 = new javax.swing.JPanel();
        javax.swing.JLabel jLabel8 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel9 = new javax.swing.JLabel();
        jTxFdEndLog = new javax.swing.JTextField();
        javax.swing.JLabel jLabel10 = new javax.swing.JLabel();
        jTxFdEndNum = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel11 = new javax.swing.JLabel();
        jTxFdEndCom = new javax.swing.JTextField();
        javax.swing.JLabel jLabel12 = new javax.swing.JLabel();
        jTxFdEndBai = new javax.swing.JTextField();
        javax.swing.JLabel jLabel13 = new javax.swing.JLabel();
        jTxFdEndCep = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel14 = new javax.swing.JLabel();
        jTxFdEndCid = new javax.swing.JTextField();
        javax.swing.JLabel jLabel15 = new javax.swing.JLabel();
        jCbBxUf = new javax.swing.JComboBox();
        javax.swing.JLabel jLabel16 = new javax.swing.JLabel();
        jTxFdEmail = new javax.swing.JTextField();
        javax.swing.JLabel jLabel17 = new javax.swing.JLabel();
        jTxFdTelFix = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel18 = new javax.swing.JLabel();
        jTxFdTelCel = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel19 = new javax.swing.JLabel();
        jTxFdComVen = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel20 = new javax.swing.JLabel();
        jTxFdDatNas = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel21 = new javax.swing.JLabel();
        jTxNom_ven = new javax.swing.JTextField();
        jBtPesquisaUsuario = new javax.swing.JButton();
        jPnlControle = new javax.swing.JPanel();
        jBtFinalizar = new javax.swing.JButton();
        jBtConfirmar = new javax.swing.JButton();
        jPnlInferior = new javax.swing.JPanel();
        javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jPnlSuperior.setBorder(new javax.swing.border.MatteBorder(null));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("SISTEMA DE ORÇAMENTOS PARA SERVIÇOS GRAFICOS");
        jLabel1.setMinimumSize(new java.awt.Dimension(0, 14));

        jLbSubTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLbSubTitulo.setText("Vendedores");
        jLbSubTitulo.setMinimumSize(new java.awt.Dimension(0, 14));

        javax.swing.GroupLayout jPnlSuperiorLayout = new javax.swing.GroupLayout(jPnlSuperior);
        jPnlSuperior.setLayout(jPnlSuperiorLayout);
        jPnlSuperiorLayout.setHorizontalGroup(
            jPnlSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
            .addComponent(jLbSubTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
        );
        jPnlSuperiorLayout.setVerticalGroup(
            jPnlSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlSuperiorLayout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLbSubTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPnlCentral.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPnlCentral.setMinimumSize(new java.awt.Dimension(100, 0));

        jPnlConteudo.setBorder(javax.swing.BorderFactory.createLineBorder(null));

        jLabel5.setText("Código:");

        jLabel6.setText("Nome:");

        jLabel7.setText("Matrícula:");

        jCkBxAtivo.setText("Ativo");

        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel8.setText("Endereço");

        jLabel9.setText("Logradouro:");

        jLabel10.setText("Número:");

        jTxFdEndNum.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));

        jLabel11.setText("Complemento:");

        jLabel12.setText("Bairro");

        jLabel13.setText("CEP:");

        try {
            jTxFdEndCep.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jTxFdEndCep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxFdEndCepActionPerformed(evt);
            }
        });

        jLabel14.setText("Cidade:");

        jLabel15.setText("UF:");

        jCbBxUf.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEndLog, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEndNum, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEndCom, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEndBai, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTxFdEndCep, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEndCid, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCbBxUf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTxFdEndLog, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTxFdEndNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jTxFdEndCom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jTxFdEndBai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jTxFdEndCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(jTxFdEndCid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCbBxUf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel16.setText("e-mail:");

        jLabel17.setText("Tel.Fixo:");

        jLabel18.setText("Tel.Celular:");

        jLabel19.setText("Comissão:");

        jLabel20.setText("Dt.Nasc.");

        jTxFdDatNas.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("##/##/####"))));

        jLabel21.setText("Usuário:");

        jTxNom_ven.setEnabled(false);

        jBtPesquisaUsuario.setText("Pesquisa");
        jBtPesquisaUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtPesquisaUsuarioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPnlConteudoLayout = new javax.swing.GroupLayout(jPnlConteudo);
        jPnlConteudo.setLayout(jPnlConteudoLayout);
        jPnlConteudoLayout.setHorizontalGroup(
            jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdNomVen, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE))
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdMatVen, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jCkBxAtivo, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE))
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE))
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addComponent(jLabel17)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdTelFix, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdTelCel, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel19)
                        .addGap(2, 2, 2)
                        .addComponent(jTxFdComVen, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdDatNas, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxNom_ven, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBtPesquisaUsuario)))
                .addContainerGap())
        );
        jPnlConteudoLayout.setVerticalGroup(
            jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTxFdCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jTxFdNomVen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTxFdMatVen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCkBxAtivo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jTxFdEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jTxFdTelFix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTxFdDatNas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(jTxFdTelCel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(jTxFdComVen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(jTxNom_ven, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtPesquisaUsuario))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        jPnlControle.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jBtFinalizar.setText("Finalizar");
        jBtFinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtFinalizarActionPerformed(evt);
            }
        });

        jBtConfirmar.setText("Confirmar");
        jBtConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtConfirmarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPnlControleLayout = new javax.swing.GroupLayout(jPnlControle);
        jPnlControle.setLayout(jPnlControleLayout);
        jPnlControleLayout.setHorizontalGroup(
            jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlControleLayout.createSequentialGroup()
                .addContainerGap(397, Short.MAX_VALUE)
                .addComponent(jBtConfirmar)
                .addGap(18, 18, 18)
                .addComponent(jBtFinalizar)
                .addContainerGap())
        );
        jPnlControleLayout.setVerticalGroup(
            jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlControleLayout.createSequentialGroup()
                .addContainerGap(12, Short.MAX_VALUE)
                .addGroup(jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtFinalizar)
                    .addComponent(jBtConfirmar))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPnlCentralLayout = new javax.swing.GroupLayout(jPnlCentral);
        jPnlCentral.setLayout(jPnlCentralLayout);
        jPnlCentralLayout.setHorizontalGroup(
            jPnlCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPnlConteudo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlControle, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPnlCentralLayout.setVerticalGroup(
            jPnlCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlCentralLayout.createSequentialGroup()
                .addComponent(jPnlConteudo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlControle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPnlInferior.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel3.setText("Gráfica Modêlo");

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Grupo de Estudo PMA Anhanguera");

        javax.swing.GroupLayout jPnlInferiorLayout = new javax.swing.GroupLayout(jPnlInferior);
        jPnlInferior.setLayout(jPnlInferiorLayout);
        jPnlInferiorLayout.setHorizontalGroup(
            jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlInferiorLayout.createSequentialGroup()
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 261, Short.MAX_VALUE)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPnlInferiorLayout.setVerticalGroup(
            jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPnlSuperior, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlInferior, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlCentral, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPnlSuperior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlCentral, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlInferior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        // TODO add your handling code here:
        jPnlControle.setBorder(null);
        jPnlConteudo.setBorder(null);
        int dif = this.getHeight()-jPnlSuperior.getHeight()-jPnlCentral.getHeight()-jPnlInferior.getHeight()-6;
        jPnlCentral.setSize(this.getWidth(),this.getHeight()-jPnlSuperior.getHeight()-jPnlInferior.getHeight()-dif);
        jPnlConteudo.setSize(jPnlCentral.getWidth()-12,jPnlCentral.getHeight()-jPnlControle.getHeight());
        jPnlControle.setSize(jPnlCentral.getWidth()-12, jPnlControle.getHeight());
        jPnlControle.setLocation(2, jPnlConteudo.getHeight());
        if (this.opcao == Menu.OP_PESQ_INC) jLbSubTitulo.setText("Inclusão Vendedores");
        if (this.opcao == Menu.OP_PESQ_ALT) jLbSubTitulo.setText("Alteração Vendedores");
    }//GEN-LAST:event_formComponentResized

    private void jTxFdEndCepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxFdEndCepActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTxFdEndCepActionPerformed

    private void jBtFinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtFinalizarActionPerformed
        // TODO add your handling code here:
        String dbMatVen=vendedor.getMat_ven()==null?"":vendedor.getMat_ven();
        String dbNomVen=vendedor.getNom_ven()==null?"":vendedor.getNom_ven();
        String dbAtivo=vendedor.getAtivo()==null?"":vendedor.getAtivo();
        String dbEndLog=vendedor.getEnd_log()==null?"":vendedor.getEnd_log();
        String dbEndNum=vendedor.getEnd_num()==null?"":vendedor.getEnd_num().toString();
        String dbEndCom=vendedor.getEnd_com()==null?"":vendedor.getEnd_com();
        String dbEndBai=vendedor.getEnd_bai()==null?"":vendedor.getEnd_bai();
        String dbEndCep=vendedor.getEnd_cep()==null?"        ":vendedor.getEnd_cep().toString();
        String dbEndCid=vendedor.getEnd_cid()==null?"":vendedor.getEnd_cid();
        String dbEndUf=vendedor.getEnd_uf()==null?"":vendedor.getEnd_uf();
        String dbEmail=vendedor.getEmail()==null?"":vendedor.getEmail();
        String dbTelFix=vendedor.getTel_fix()==null?"":vendedor.getTel_fix();
        String dbTelCel=vendedor.getTel_cel()==null?"":vendedor.getTel_cel();
        String dbComVen=vendedor.getCom_ven()==null?"":vendedor.getCom_ven().toString();
//        String dbDatNas=vendedor.getDat_nas()==null?"":vendedor.getDat_nasForm();
        String dbDatNas=vendedor.getDat_nasForm();
        String igAtivo=jCkBxAtivo.isEnabled()?"S":"N";
        String igEndCep=jTxFdEndCep.getText();
        igEndCep=igEndCep.substring(0,2)+igEndCep.substring(3,6)+igEndCep.substring(7,10);
        String igEndUf="";
        if (jCbBxUf.getSelectedItem()!=null){
            igEndUf=jCbBxUf.getSelectedItem().toString();
        }
        boolean b1= !jTxFdMatVen.getText().equals(dbMatVen);
        boolean b2= !jTxFdNomVen.getText().equals(dbNomVen);
//        boolean b3= !igAtivo.equals(dbAtivo);
        boolean b4= !jTxFdEndLog.getText().equals(dbEndLog);
        boolean b5= !jTxFdEndNum.getText().equals(dbEndNum);
        boolean b6= !jTxFdEndCom.getText().equals(dbEndCom);
        boolean b7= !jTxFdEndBai.getText().equals(dbEndBai);
        boolean b8= !igEndCep.equals(dbEndCep);
        boolean b9= !jTxFdEndCid.getText().equals(dbEndCid);
//        boolean b10= !jCbBxUf.getSelectedItem().equals(dbEndUf);
        boolean b11= !jTxFdEmail.getText().equals(dbEmail);
        boolean b12= !jTxFdTelFix.getText().equals(dbTelFix);
        boolean b13= !jTxFdTelCel.getText().equals(dbTelCel);
        boolean b14= !jTxFdComVen.getText().equals(dbComVen);
        boolean b15= !jTxFdDatNas.getText().equals(dbDatNas);
        if (!jTxFdMatVen.getText().equals(dbMatVen)||
            !jTxFdNomVen.getText().equals(dbNomVen)||
//            !igAtivo.equals(dbAtivo)||
            !jTxFdEndLog.getText().equals(dbEndLog)||
            !jTxFdEndNum.getText().equals(dbEndNum)||
            !jTxFdEndCom.getText().equals(dbEndCom)||
            !jTxFdEndBai.getText().equals(dbEndBai)||
            !igEndCep.equals(dbEndCep)||
            !jTxFdEndCid.getText().equals(dbEndCid)||
            !igEndUf.equals(dbEndUf)||
            !jTxFdEmail.getText().equals(dbEmail)||
            !jTxFdTelFix.getText().equals(dbTelFix)||
            !jTxFdTelCel.getText().equals(dbTelCel)||
            !jTxFdComVen.getText().equals(dbComVen)||
            !jTxFdDatNas.getText().equals(dbDatNas)
                ){
            if (javax.swing.JOptionPane.showConfirmDialog(null,
                    "Modificações foram feitas, deseja realmente finalizar sem salvar ?",
                    "Finalizar", javax.swing.JOptionPane.YES_NO_OPTION)==0){
               Vendedores.this.dispose();
            }
        } else Vendedores.this.dispose();
    }//GEN-LAST:event_jBtFinalizarActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        vendedorControler.liberarVendedor(); 

    }//GEN-LAST:event_formWindowClosed

    private void jBtConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtConfirmarActionPerformed
        // TODO add your handling code here:
        boolean gravarOk = true;
        String mensErro="Dados não puderam ser salvos, apresentaram os seguintes erro:";
        String igUf= null;
        if (jCbBxUf.getSelectedIndex()<0){
            gravarOk=false;
            mensErro+="\nDeve ser selecionada ua unidade federativa no endereço";
        } else {
            igUf=jCbBxUf.getSelectedItem().toString();
        }
        String igEndCep=jTxFdEndCep.getText().replaceAll("\\.", "");
        igEndCep=igEndCep.replaceAll("-", "");
        String igEndNum=jTxFdEndNum.getText().replaceAll("\\.", "");
        String igComVen=jTxFdComVen.getText().replaceAll("\\.", "");
        igComVen=jTxFdComVen.getText().replaceAll(",", ".");
        if (jTxFdNomVen==null||jTxFdNomVen.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo nome deve ser preenchido";
        }
        if (jTxFdMatVen==null||jTxFdMatVen.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo matrícula deve ser preenchido";
        }
        if (jTxFdEndLog==null||jTxFdEndLog.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo logradouro no endereço deve ser preenchido";
        }
        if (jTxFdEndCep==null||igEndCep.equals("")){
            gravarOk=false;
            mensErro+="\nO campo CEP no endereço deve ser preenchido";
        }
        if (jTxFdEndCid==null||jTxFdEndCid.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo cidade no endereço deve ser preenchido";
        }
        if (igUf==null||igUf.equals("")){
            gravarOk=false;
            mensErro+="\nO campo UF no endereço deve ser preenchido";
        }
        if (jTxFdEmail==null||jTxFdEmail.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo Email deve ser preenchido";
        }
        if (jTxFdTelCel==null||jTxFdTelCel.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo Telefone Celular deve ser preenchido";
        }
        if (jTxFdComVen==null||jTxFdComVen.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo Comissão deve ser preenchido";
        }
        if (usuario==null&&vendedor.getUsuario()==null){
            gravarOk=false;
            mensErro+="\nO usuario do vendedor precisa ser informado";
        }
        if (!Menu.validaData(jTxFdDatNas.getText())){
            gravarOk=false;
            mensErro+="\nData de Nascimento invalida";
        }
        if (!gravarOk){
           javax.swing.JOptionPane.showMessageDialog(null,
                   mensErro+"\n"
                   + "Corrija as infromações listadas e tente confirmar novamente ",
                   "Acesso ao Banco de Dados", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            vendedor.setNom_ven(jTxFdNomVen.getText());
            vendedor.setMat_ven(jTxFdMatVen.getText());
            vendedor.setAtivo(jCkBxAtivo.isEnabled()?"S":"N");
            vendedor.setEnd_log(jTxFdEndLog.getText());
            vendedor.setEnd_num(Integer.parseInt(igEndNum));
            vendedor.setEnd_com(jTxFdEndCom.getText());
            vendedor.setEnd_bai(jTxFdEndBai.getText());
            vendedor.setEnd_cep(Integer.parseInt(igEndCep));
            vendedor.setEnd_cid(jTxFdEndCid.getText());
            vendedor.setEnd_uf(jCbBxUf.getSelectedItem().toString());
            vendedor.setEmail(jTxFdEmail.getText());
            vendedor.setTel_fix(jTxFdTelFix.getText());
            vendedor.setTel_cel(jTxFdTelCel.getText());
            vendedor.setCom_ven(igComVen);
            vendedor.setDat_nas(jTxFdDatNas.getText());
            if (usuario!=null){
                vendedor.setUsuario(usuario);
            }
            if (this.opcao == Menu.OP_PESQ_ALT){
               if (!vendedorControler.alterarVendedor(vendedor)){
                  javax.swing.JOptionPane.showMessageDialog(null,
                    "Erro na atualização dos dados do vendedor",
                    "Acesso ao Banco de Dados",
                    javax.swing.JOptionPane.INFORMATION_MESSAGE);
                }
            } else if (this.opcao == Menu.OP_PESQ_INC){
                boolean teste=vendedorControler.adicionarVendedor(vendedor);
                if (!teste){
                    javax.swing.JOptionPane.showMessageDialog(null,
                        "Erro na inclusão do vendedor",
                        "Acesso ao Banco de Dados",
                        javax.swing.JOptionPane.INFORMATION_MESSAGE);
                } this.incluiu = true;
            }
            Vendedores.this.dispose();
        }
    }//GEN-LAST:event_jBtConfirmarActionPerformed

    private void jBtPesquisaUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtPesquisaUsuarioActionPerformed
        // TODO add your handling code here:
       PesquisaUsuarios pesquisaUsuarios = new PesquisaUsuarios(new javax.swing.JFrame(), true);
       usuario = new Usuario();
       pesquisaUsuarios.setUsuario(usuario);
       pesquisaUsuarios.setOpcao(0);
       usuario = pesquisaUsuarios.getUsuario();
       pesquisaUsuarios.dispose();
       jTxNom_ven.setText(usuario.getNome());

    }//GEN-LAST:event_jBtPesquisaUsuarioActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtConfirmar;
    private javax.swing.JButton jBtFinalizar;
    private javax.swing.JButton jBtPesquisaUsuario;
    private javax.swing.JComboBox jCbBxUf;
    private javax.swing.JCheckBox jCkBxAtivo;
    private javax.swing.JLabel jLbSubTitulo;
    private javax.swing.JPanel jPnlCentral;
    private javax.swing.JPanel jPnlConteudo;
    private javax.swing.JPanel jPnlControle;
    private javax.swing.JPanel jPnlInferior;
    private javax.swing.JPanel jPnlSuperior;
    private javax.swing.JTextField jTxFdCodigo;
    private javax.swing.JFormattedTextField jTxFdComVen;
    private javax.swing.JFormattedTextField jTxFdDatNas;
    private javax.swing.JTextField jTxFdEmail;
    private javax.swing.JTextField jTxFdEndBai;
    private javax.swing.JFormattedTextField jTxFdEndCep;
    private javax.swing.JTextField jTxFdEndCid;
    private javax.swing.JTextField jTxFdEndCom;
    private javax.swing.JTextField jTxFdEndLog;
    private javax.swing.JFormattedTextField jTxFdEndNum;
    private javax.swing.JTextField jTxFdMatVen;
    private javax.swing.JTextField jTxFdNomVen;
    private javax.swing.JFormattedTextField jTxFdTelCel;
    private javax.swing.JFormattedTextField jTxFdTelFix;
    private javax.swing.JTextField jTxNom_ven;
    // End of variables declaration//GEN-END:variables

}
